#ifndef _MSG_DEF_H
#define _MSG_DEF_H

#include "common.h"


typedef struct 
{
   int statusCode;
   int errorNum;
   int sid;
   int moduleId;
}msgAck;

typedef struct 
{
    long type;
    msgAck msg;
}msgQueueAck;

typedef enum
{
    PARAM_INVALID = 1,
    ACT_TIMEOUT_GRPC = 2,
    ACT_MSG_ERROR = 3,
    ACT_ALREADY_RUNNINMG =4,
    ACT_DETECT_LIQUID_FAILED = 5,
    ACT_TIMEOUT_APP = 6,
}en_errCode;

// #if  defined(__x86_64)
// #define msgQueueKeyPath "/home/hcgy/Documents/esm6800h/test/msg.tmp"
// #define msgNotifyQueuePath "/home/hcgy/Documents/esm6800h/test/msgNotify.tmp" 
// #else
// #define msgQueueKeyPath "/home/usr/msg/msg.tmp"
// #define msgNotifyQueuePath "/home/usr/msg/msgNotify.tmp"
// #endif

#if  defined(__x86_64)
#define msgQueueKeyPath "/home/hcgy/Documents/esm6800h/test/msg.tmp"
#define msgNotifyQueuePath "/home/hcgy/Documents/esm6800h/test/msgNotify.tmp" 
#define msgQueueKeyQ1Path "/home/hcgy/Documents/esm6800h/test/msgQ1.tmp"
#define msgNotifyQueueQ1Path "/home/hcgy/Documents/esm6800h/test/msgNotifyQ1.tmp"
#define msgLuaQueuePath "/home/hcgy/Documents/esm6800h/test/msgLua.tmp"
#define SOCK_IPC_FILE "/home/hcgy/Documents/esm6800h/test/sock_ipc.txt"
#define SOCK_IPC_NOTIFY "/home/hcgy/Documents/esm6800h/test/sock_notify.txt" 
#else
#define msgQueueKeyPath "/home/usr/msg/msg.tmp"
#define msgNotifyQueuePath "/home/usr/msg/msgNotify.tmp"
#define msgQueueKeyQ1Path "/home/usr/msg/msgQ1.tmp"
#define msgNotifyQueueQ1Path "/home/usr/msg/msgNotifyQ1.tmp"
#define msgLuaQueuePath "/home/usr/msg/msgLua.tmp"
#define SOCK_IPC_FILE "/home/usr/msg/sock_ipc.txt"
#define SOCK_IPC_NOTIFY "/home/usr/msg/sock_notify.txt" 
#endif

#define keyNotifyMsg   0x1236
#define keyNotifyMsg_1 0x1237

#define keyMsg_QPCR1 0x1238

#define keyMsg_LUA 0x1239

typedef enum
{
    QUEUE_MSG_TYPE_UIM=1,
    QUEUE_MSG_TYPE_BOARDS=2,
    QUEUE_MSG_TYPE_GRPC=3,
    QUEUE_MSG_TYPE_RS485=4,
    QUEUE_MSG_TYPE_MODULE=5,
    QUEUE_MSG_TYPE_SAMPLE=6,
    QUEUE_MSG_TYPE_REPORT=7,
    QUEUE_MSG_TYPE_LUA=8,
}en_queue_msg_type;


typedef struct _wontec_msg_def
{
    /* data */
    char tarDev;
    unsigned char funcCode;
    unsigned char paramLen;
    char paramData[50];
    char msgSrc;
}wontec_msg_def;

typedef struct _wontec_queue_msg
{
    int type;
    wontec_msg_def wontecMsg; 
}wontec_queue_msg;

typedef struct _dj_move_param
{
    int initX;
    int initY;
    int initZ;

    int deltaX;
    int deltaY;
    
    int numStepsOneAct;
}dj_move_param;

typedef struct _dj_reagent
{
     int quantity_suck; // the quantity
     int quantity_air;
     int quantity_spit;
}dj_reagent;

typedef struct _tube_trans
{
     int Xsrc; 
     int Ysrc;
     int Zsrc;
     
     int Xtar; 
     int Ytar;
	 int Ztar;

}tube_trans;

typedef struct _dp8_lld
{
    int threshold;
    int speed;
    int maxPosition;
    int acc;
    int dec;
}dp8_lld;

typedef struct _dp8capsample
{
    int position;
    int speed;    
    int acc;
    int dec;
    int interval;
    unsigned char chanMask;
}dp8capSample;


typedef struct _module_msg
{
    int moduleId;
    union msgParam
    {
        move_param moveParam;
        dj_move_param djMoveParam;
        dj_reagent djReagentParam;
        tube_trans tubeTransParam;
        dp8_lld dp8lldParam;
        dp8capSample dp8capSampleParam;
        /* data */
    }un_param;   
    
}module_msg;

typedef struct _module_queue_msg
{
    int type;
    module_msg moduleMsg;

}module_queue_msg;

typedef enum
{
    TEMPRATURE_SAMPLE,
    CAPACITY_SAMPLE,
}en_sample_data_type;

typedef enum
{
    START_SAMPLE,
    STOP_SAMPLE,
}en_sample_act_type;

typedef struct _sample_msg
{
    int boardId;
    int data_type;
    int act_type;
    int chan;
}sample_msg;

typedef struct _sample_queue_msg
{
    int type;
    sample_msg sampleMsg;

}sample_queue_msg;

typedef struct _report_up
{
   union
   {
       struct {
           int devId;
           int status;
       }st_status;
       
   }un_msg;
}report_up;

typedef struct _report_up_queue
{
    int type;
    report_up msgReport;
}report_up_queue;


typedef struct _dj_act
{
    pos_dj refPos;//position for Aa
    int deltaX;
    int deltaY;
    int numActOneCycle;
}dj_actParam;

extern int g_msg_id;

typedef enum
{
    MSG_FROM_TEST,
    MSG_FROM_GRPC,
    MSG_FROM_LUA,
}en_msg_src;


typedef struct _msgAckLua
{
   int type;
   recvDataEleCtl eleStatus;
}msgAckLua;

void sendAckToLua(void * ackDataIn);


void sendAckToLua(int sidIn, int status);

typedef struct _sockActMsg
{
    int moduleType;
    int actType;
    int paramType;
    int paramLen;
}sockActMsg;

typedef struct _msgAckSock
{
    int moduleType;
    int actType;
    int component;
    int status;
    int errorCode;
}msgAckSock;

#define AXIS_X_MASK 0x00000001
#define AXIS_Y_MASK 0x00000002
#define AXIS_Z_MASK 0x00000004
#define AXIS_JAW_Z_MASK 0x00000008
#define AXIS_JAW_MASK 0x00000010
#define AXIS_PUMP_MASK 0x00000020

typedef enum
{
   ACT_SINGLE_INIT,
   ACT_MODULE_INIT,
   ACT_SINGLE_MOVE,
   ACT_PARRAL_MOVE,   
   ACT_CHAIN_ACTION,
   ACT_SUCK_LIQUID,
   ACT_SPIT_LIQUID,
   ACT_SPIT_LIQUID_MULTI,
   ACT_TIP_CTL,
   ACT_TEMPERATURE_READ,
   ACT_SCANCODE_CTL, 
   ACT_DRAWER_CTL, 
   ACT_DJ_CLEAN_CTL, 
   ACT_HEAT_CTL, 
   ACT_SHAKE_CTL,
   ACT_JAW_TRANS,
   ACT_SUCK1_SPITM,
   ACT_SCHEME_CTL,
   ACT_PLUNGER_PUMP,
   ACT_LIGHT_CTL,
   ACT_TRANS_BOARD,   
}en_act_type;

typedef enum
{
   PARAM_AXIS_MOVE_STEPS,
   PARAM_AXIS_MOVE_POS,
   PARAM_LIQUID_CTL,
   PARAM_SUCK1_SPIT1,
   PARAM_SUCK1_SPIT_MULTI,
   PARAM_TIMEOUT,
   PARAM_TEMPRATURE,
   PARAM_GET_TIP,
   PARAM_DROP_TIP,
   PARAM_SHAKE_CTL,
   PARAM_SMOOTH_CTL,
   PARAM_OPENLID_CTL,
   PARAM_SEAL_CTL,
   PARAM_JAW_TRANS,
   PARAM_JAW_TRANS_FILM,
   PARAM_JAW_CTL,
   PARAM_JAW_CTL_FILM,
   PARAM_LOGISTIC_MOVE,
}en_beta_param_type;


typedef enum
{
    EXPECT_NO_DATA,
    EXPECT_INT_DATA,
    EXPECT_FLOAT_DATA,
}en_data_type;


typedef enum {
  MT_AXIS_X = 0, //X����/ƽ���˶���һ��ģ����(����ģ��������Ƴ����������ԡ�����Ƴ����)
  MT_AXIS_Y = 1, //Y����
  MT_AXIS_Z = 2, //Z����
  MT_JAW_Z = 3, //��צZ����
  MT_JAW = 4, //��צ�źϵ��
  MT_PUMP = 5, //��Һ/��Һ�����õ��
  MT_QUIT_TIP_Z = 6,
  MT_DP8_1_AXIS_Z = 7,
  MT_DP8_ABANDONED_HATCH = 8, //DP8 废弃回收舱门电机
  // 物流模块
  MT_LOGISTICS1_Y = 9, // 第一物流单元Y轴电机
  MT_LOGISTICS1_Z = 10, // 第一物流单元Z轴电机
  MT_LOGISTICS2_BASE_X = 11, // 第二物流单元底座X轴电机
  MT_LOGISTICS2_TRAY_X = 12, // 第二物流单元托盘X轴电机
  

  MT_JAW_X = 13,        // 夹爪X轴电机
  MT_LOGISTICS3_TRAY_Z =14,        // 托盘Z轴电机
  // QPCR模块
  MT_OPTICAL = 15, // 切换滤光片通道电机
  MT_PUMP_SMALL = 16,
}en_motor_type;

typedef enum
{
    NOTIFY_DJCLEAN_WATER_LESS,
    NOTIFY_SCAN_CODE,//for scan code report
    NOTIFY_QPCR_PHOTO,
    NOTIFY_CURR_TEMP,//report the current temperature  
    NOTIFY_STAGE_INFO,//report the current purify stage info 
}en_notify_type;

//report temperature
typedef struct _temp_report_msg
{
    unsigned char boardId;
    unsigned char chanNum;
    unsigned char reserve1;
    unsigned char reserve2;
    float currTemp;
}temp_report_msg;

typedef struct _report_up_msg
{
    int type;
    int dataLen;
    union
    {
      int waterLessMask;
      int barcodeChan;
      int qpcrNotify; 
      temp_report_msg tempReportMsg;
    }un_msg_data;
}report_up_msg;

#endif
